<%#
    # mainNav  : 主导航元素组对象
    #   *.leftList  : 主导航栏左侧导航元素
    #   *.rightList : 主导航栏右侧导航元素（登陆）
    #       *.text  : 导航标题
    #       *.link  : 导航链接
    #       *.sty   : 元素样式类
    #   *.loginFlag : 判断用户是否登陆
#%>
<style>
    /* 导航栏基本样式 */
.main-nav {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background-color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  transition: transform 0.3s ease, background-color 0.3s ease;
}

.nav-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* 导航栏滚动效果 */
.main-nav.scrolled {
  background-color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 15px rgba(0, 0, 0, 0.15);
}

.main-nav.nav-hidden {
  transform: translateY(-100%);
}

/* 左侧导航 */
.nav-left {
  display: flex;
  align-items: center;
}

.home-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: #333;
  margin-right: 1.5rem;
}

.home-link img {
  margin-right: 0.5rem;
}

.nav-links {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  margin: 0 0.8rem;
}

.nav-item a {
  color: #333;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
  padding: 0.5rem 0;
  position: relative;
}

.nav-item a:hover {
  color: #007bff;
}

.nav-item a:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 2px;
  background-color: #007bff;
  transition: width 0.3s ease;
}

.nav-item a:hover:after {
  width: 100%;
}

/* 搜索栏 */
.search-container {
  flex: 0 1 300px;
}

.search-form {
  width: 100%;
}

.search-input-wrapper {
  display: flex;
  border: 1px solid #ddd;
  border-radius: 20px;
  overflow: hidden;
  transition: box-shadow 0.3s ease;
}

.search-input-wrapper.focused {
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
  border-color: #007bff;
}

.search-input {
  flex: 1;
  border: none;
  padding: 0.5rem 1rem;
  outline: none;
  font-size: 0.9rem;
}

.search-button {
  background: none;
  border: none;
  padding: 0.5rem 1rem;
  cursor: pointer;
  color: #666;
  transition: color 0.2s ease;
}

.search-button:hover {
  color: #007bff;
}

/* 右侧导航 */
.nav-right {
  display: flex;
  align-items: center;
}

.auth-links {
  display: flex;
  align-items: center;
}

.notice-link {
  margin-right: 1.5rem;
  color: #666;
  text-decoration: none;
  font-size: 0.9rem;
}

.login-register {
  display: flex;
  align-items: center;
}

.login-button, .register-button {
  color: #333;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.login-button:hover, .register-button:hover {
  color: #007bff;
}

.divider {
  margin: 0 0.5rem;
  color: #999;
}

/* 移动端菜单按钮 */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.hamburger-icon {
  display: block;
  width: 24px;
  height: 2px;
  background-color: #333;
  position: relative;
  transition: background-color 0.3s ease;
}

.hamburger-icon:before,
.hamburger-icon:after {
  content: '';
  position: absolute;
  width: 24px;
  height: 2px;
  background-color: #333;
  transition: transform 0.3s ease;
}

.hamburger-icon:before {
  top: -6px;
}

.hamburger-icon:after {
  bottom: -6px;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon {
  background-color: transparent;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon:before {
  transform: rotate(45deg);
  top: 0;
}

.mobile-menu-toggle[aria-expanded="true"] .hamburger-icon:after {
  transform: rotate(-45deg);
  bottom: 0;
}

/* 移动端菜单 */
.mobile-menu {
  display: none;
  position: fixed;
  top: 60px;
  left: 0;
  width: 100%;
  background-color: #fff;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
  padding: 1rem;
  z-index: 999;
  transform: translateY(-100%);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.mobile-menu.active {
  transform: translateY(0);
  opacity: 1;
}

.mobile-search {
  margin-bottom: 1rem;
}

.mobile-nav-links,
.mobile-user-links {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem 0;
}

.mobile-nav-item {
  margin: 0.5rem 0;
}

.mobile-nav-item a {
  display: block;
  padding: 0.5rem 0;
  color: #333;
  text-decoration: none;
  font-weight: 500;
}

.mobile-auth {
  border-top: 1px solid #eee;
  padding-top: 1rem;
}

.mobile-notice-link {
  display: block;
  margin-bottom: 1rem;
  color: #666;
  text-decoration: none;
}

.mobile-login-register {
  display: flex;
  align-items: center;
}

.mobile-login-button,
.mobile-register-button {
  color: #333;
  text-decoration: none;
  font-weight: 500;
}

.mobile-divider {
  margin: 0 0.5rem;
  color: #999;
}

/* 响应式设计 */
@media (max-width: 992px) {
  .desktop-only {
    display: none;
  }
  
  .mobile-menu-toggle {
    display: block;
  }
  
  .nav-container {
    padding: 0.5rem 1rem;
  }
  
  .search-container {
    flex: 0 1 200px;
  }
  
  .mobile-menu {
    display: block;
  }
  
  body.menu-open {
    overflow: hidden;
  }
}

@media (max-width: 768px) {
  .search-container {
    display: none;
  }
  
  .nav-right .auth-links {
    display: none;
  }
  
  .nav-container {
    justify-content: space-between;
  }
}

@media (min-width: 993px) {
  .mobile-menu {
    display: none !important;
  }
}

</style>

<nav class="main-nav container-fluid">
  <div class="nav-container">
    <!-- 移动端菜单按钮 -->
    <button class="mobile-menu-toggle" aria-label="菜单" aria-expanded="false">
      <span class="hamburger-icon"></span>
    </button>
    
    <!-- 左侧导航 -->
    <div class="nav-left">
      <a href="/" class="home-link">
        <img src="/images/little_logo.png" alt="网站Logo" width="30" height="30">
        <span>首页</span>
      </a>
      
      <ul class="nav-links desktop-only">
        <% mainNav.leftList.forEach(function (item) { %>
          <li class="nav-item">
            <a href="<%= item.link %>" class="<%= item.sty %>"><%= item.text %></a>
          </li>
        <% }) %>
      </ul>
    </div>
    
    <!-- 搜索栏 -->
    <div class="search-container">
      <form class="search-form" role="search">
        <div class="search-input-wrapper">
          <input type="search" placeholder="搜索内容..." aria-label="搜索" class="search-input">
          <button type="submit" class="search-button" aria-label="搜索">
            <i class="fa fa-search" aria-hidden="true"></i>
          </button>
        </div>
      </form>
    </div>
    
    <!-- 右侧导航 -->
    <div class="nav-right">
      <% if (mainNav.loginFlag) { %>
        <!-- 已登录状态 -->
        <ul class="nav-links user-links">
          <% mainNav.rightList.forEach(function (item) { %>
            <li class="nav-item">
              <a href="<%= item.link %>" class="<%= item.sty %>"><%= item.text %></a>
            </li>
          <% }) %>
        </ul>
      <% } else { %>
        <!-- 未登录状态 -->
        <div class="auth-links">
          <a href="/inboundNotice" class="notice-link">入站须知</a>
          <div class="login-register">
            <a href="/login" class="login-button">登录</a>
            <span class="divider">/</span>
            <a href="/register" class="register-button">注册</a>
          </div>
        </div>
      <% } %>
    </div>
  </div>
  
  <!-- 移动端导航菜单 -->
  <div class="mobile-menu">
    <div class="mobile-search">
      <form class="search-form-mobile" role="search">
        <input type="search" placeholder="搜索内容..." aria-label="搜索" class="search-input-mobile">
        <button type="submit" class="search-button-mobile" aria-label="搜索">
          <i class="fa fa-search" aria-hidden="true"></i>
        </button>
      </form>
    </div>
    
    <ul class="mobile-nav-links">
      <% mainNav.leftList.forEach(function (item) { %>
        <li class="mobile-nav-item">
          <a href="<%= item.link %>" class="<%= item.sty %>"><%= item.text %></a>
        </li>
      <% }) %>
    </ul>
    
    <div class="mobile-auth">
      <% if (mainNav.loginFlag) { %>
        <!-- 已登录状态 -->
        <ul class="mobile-user-links">
          <% mainNav.rightList.forEach(function (item) { %>
            <li class="mobile-nav-item">
              <a href="<%= item.link %>" class="<%= item.sty %>"><%= item.text %></a>
            </li>
          <% }) %>
        </ul>
      <% } else { %>
        <!-- 未登录状态 -->
        <a href="/inboundNotice" class="mobile-notice-link">入站须知</a>
        <div class="mobile-login-register">
          <a href="/login" class="mobile-login-button">登录</a>
          <span class="mobile-divider">/</span>
          <a href="/register" class="mobile-register-button">注册</a>
        </div>
      <% } %>
    </div>
  </div>
</nav>

<!-- 导航栏交互脚本 -->
<script>
  document.addEventListener('DOMContentLoaded', function() {
    // 移动菜单切换
    const menuToggle = document.querySelector('.mobile-menu-toggle');
    const mobileMenu = document.querySelector('.mobile-menu');
    
    if (menuToggle && mobileMenu) {
      menuToggle.addEventListener('click', function() {
        const expanded = this.getAttribute('aria-expanded') === 'true';
        this.setAttribute('aria-expanded', !expanded);
        mobileMenu.classList.toggle('active');
        document.body.classList.toggle('menu-open');
      });
    }
    
    // 搜索框焦点效果
    const searchInputs = document.querySelectorAll('.search-input, .search-input-mobile');
    searchInputs.forEach(input => {
      input.addEventListener('focus', function() {
        this.parentElement.classList.add('focused');
      });
      
      input.addEventListener('blur', function() {
        this.parentElement.classList.remove('focused');
      });
    });
    
    // 滚动时导航栏效果
    let lastScrollTop = 0;
    const nav = document.querySelector('.main-nav');
    
    window.addEventListener('scroll', function() {
      const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
      
      if (scrollTop > 50) {
        nav.classList.add('scrolled');
      } else {
        nav.classList.remove('scrolled');
      }
      
      if (scrollTop > lastScrollTop && scrollTop > 200) {
        nav.classList.add('nav-hidden');
      } else {
        nav.classList.remove('nav-hidden');
      }
      
      lastScrollTop = scrollTop;
    });
  });
</script>
